#include "../include/MsgString.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

CMsgString::CMsgString(void)
{
	m_DataSize = 2048;
	m_pData = (LPTSTR)new TCHAR[m_DataSize];
	memset( m_pData, 0, m_DataSize );
	m_Length = 0;
}


CMsgString::~CMsgString(void)
{
	delete m_pData;
}

LPTSTR CMsgString::GetData()
{
	return m_pData;
}

int CMsgString::GetLength()
{
	return m_Length;
}

void CMsgString::Format( const TCHAR *a_pFormat,... )
{
	va_list vl;
	va_start(vl, a_pFormat );

	// Expand space
	int needSize = _sntprintf(NULL,0,a_pFormat, vl );
	if( this->m_DataSize <= needSize )
	{
		delete this->m_pData;
		this->m_pData = new TCHAR[needSize];
		this->m_DataSize = needSize;
	}

	m_Length = needSize;

	_vstprintf( m_pData, a_pFormat, vl );
}

void CMsgString::ToString( tstring &a_str )
{
	a_str.assign( (const LPTSTR)this->m_pData, this->m_Length );
}
